﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Bll;
using AspNetCs.Common;

public partial class Users_Login : Pub_Label
{
    protected Users UsersCreate = new Users();
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!Page.IsPostBack)
        {
            Login_ReUrl();
        }

    }
    /// <summary>
    /// 返回页面地址
    /// </summary>
    protected void Login_ReUrl()
    {
        string resultReUrl = "";
        if (Request["ReUrl"] != null)
        {
            resultReUrl = Server.UrlDecode(Request["ReUrl"].ToString());
        }
        if (resultReUrl + "" == "")
        {
            resultReUrl = configInfo.InstallDir;
        }
        ViewState["ReUrl"] = resultReUrl;

    }


    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {

        string UserName = Txt_UserName.Text.ToString();
        string Pwd = Txt_Pwd.Text.ToString();
        string CodeStr = CheckCode.Text.ToString();
        if (Session["CheckCode"] != null && CodeStr.ToString().Trim().ToLower() != "")
        {
            if (CodeStr.ToString().ToLower().Trim() != Session["CheckCode"].ToString().ToLower().Trim())
            {
                ShowMsgBack("请输入正确的验证码！");
                Response.End();
            }
        }
        else
        {
            ShowMsgBack("请输入正确的验证码！");
            Response.End();
        }
        int Exp = StringHelper.isNumber_int(CookExp.SelectedValue);
        if (new UserSave_Property().Types == 1)
        {
            Exp = configInfo.SessionTimeOut;
        }
        else
        {
            Exp = (Exp * 60 * 60 * 24);
        }
        string msg = "";
        if (UsersCreate.UserLogin(UserName, EncryptString.md5(Pwd), Exp, configInfo.DayAddIntegral, out msg) != 1)
        {
            ShowMsgBack(msg);
            Response.End();
        }
        else
        {
            Response.Redirect(ViewState["ReUrl"].ToString());
            Response.End();
        }




    }
}
